package com.example.grpcserver.service;

import com.example.proto.NewsProto;
import com.example.proto.NewsServiceGrpc;
import io.grpc.stub.StreamObserver;
import net.devh.boot.grpc.server.service.GrpcService;

@GrpcService // 注册为grpc服务
public class NewsService extends NewsServiceGrpc.NewsServiceImplBase {

    /**
     * 重写定义的方法
     */
    @Override
    public void hello(NewsProto.StringRequest request, StreamObserver<NewsProto.StringResponse> responseObserver) {
        System.out.println("收到grpc请求：" + request);
        NewsProto.StringResponse stringResponse = NewsProto.StringResponse.newBuilder()
                .setResult("hi, " + request.getName())
                .build();
        responseObserver.onNext(stringResponse);
        responseObserver.onCompleted();
    }
}
